package fk_snake

import (
	"gitee.com/lwow2025/snake-go/draw-by-gocui"
	"gitee.com/lwow2025/snake-go/game"
	"gitee.com/lwow2025/snake-go/config"
)

func NewSnakeGame(playerCount int) *App {
	if playerCount <= 0 {
		panic("player count must bigger chan 0")
	}

	// prepare app
	app := &App{}

	// init ui
	ui := draw_by_gocui.NewSnakeUI(func() {
		app.Stop()
	})

	// init players
	snakes := []game.AbsSnake{ game.NewSnake(config.Player1, ui) }
	if playerCount > 1 {
		snakes = append(snakes, game.NewSnake(config.Player2, ui))
	}
	// init game
	g := game.NewGame(ui, snakes, ui)
	ui.SetPerformer(g)

	app.services = []appService{ ui, g, }

	return app
}
